package com.sian.anyun.web.security;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Service;

import com.sian.security.web.model.Authority;
import com.sian.security.web.model.Credential;
import com.sian.security.web.model.Permission;
import com.sian.security.web.service.AbstractSecurityService;

@Service
public class MySecurityService extends AbstractSecurityService
{

	public void authenticate(Credential credential)
	{
		// TODO: Authenticate credential
		// Mock up
		List<Authority> authorities = new ArrayList<Authority>();
		List<Permission> permissions = new ArrayList<Permission>();
		
		Permission readPermission = new Permission();
		readPermission.setResourceName("resourceName");
		readPermission.setPermit(Permission.PERMIT_READ);
		permissions.add(readPermission);
		
		Permission writePermission = new Permission();
		writePermission.setResourceName("resourceName");
		writePermission.setPermit(Permission.PERMIT_WRITE);
		permissions.add(writePermission);
		
		Authority authority = new Authority();
		authority.setRoleName("ROLE_USER");
		authority.setPermissions(permissions);
		
		authorities.add(authority);
		
		this.setCredential(credential);
		this.setAuthorities(authorities);
	}
}
